<?php

class Crawl {

    /**
     * Get data from a url
     * @param type $url
     * @return type 
     */
    public function getPage($url) {
        $ch = curl_init();
        $timeout = 5;

        // Settings
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11');
        //
        $data = curl_exec($ch);
        curl_close($ch);

        return $data;
    }
    
    public function parseData($data, $pattern) {
        $results = NULL;
        preg_match_all($pattern, $data, $matches);
        if (!empty($matches[1])) {
            $results = $matches;
        }
        
        return $results;
    }

}
